<!-- 分割线组件 -->
<template>
    <uiwu-popup v-model="showPopup" v-if="showPopup">
        <view v-if="poplist.length" style="width: 100%;height: 100%;padding-bottom: 128rpx;"
            class="flex flex-col justify-center items-center">

            <view @tap.stop>
                <uiwu-icon @click="closePopup" type="closeempty" size="24" color="#FFF" />
            </view>
            <image @tap.stop="openPopup" :src="poplist[popindex].image" mode="widthFix" style="width: 70%;"></image>
        </view>
    </uiwu-popup>
</template>

<script lang="ts" setup>
import type { Advert as AdverInterface } from '@/api/type/interface';
import { ref, toRefs, watch } from 'vue';

const popindex = ref(0);
const showPopup = ref(false);
const props = defineProps(
    {
        poplist: {
            default: [],
            type: Array
        }
    }
);

const { poplist } = toRefs(props);
console.log(poplist.value, "advert props");



const closePopup = () => {
    if (popindex.value == poplist.value.length - 1) return showPopup.value = false
    popindex.value++
}
const openPopup = (): void => {
    const { is_tab, path } = poplist.value[popindex.value] as AdverInterface;
    if (is_tab) uni.switchTab({
        url: path
    })
    if (!is_tab) uni.navigateTo({
        url: path
    })
    showPopup.value = false
}

watch(props, () => {
    if (poplist.value.length) {
        showPopup.value = true;
    }
});

</script>

<style scoped lang="scss"></style>